package com.njtoyo.taxi.admin.rest.controller.local_service.merchant;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njtoyo.taxi.admin.mapper.master.entity.local_service.GeoMerchantRegion;
import com.njtoyo.taxi.admin.rest.presenter.local_service.platform.MerchantCategoryPagePresenter;
import com.njtoyo.taxi.admin.rest.wrapper.local_service.platform.MerchantWrapper;
import com.njtoyo.taxi.admin.service.local_service.merchant.MerchantRegionService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

@RestController
@Api(value = "商户运营区管理", tags = "商户运营区管理")
@RequestMapping("local-service/merchant-region")
public class MerchantRegionController {

    @Autowired
    private MerchantRegionService regionService;

    @GetMapping("/all")
    @ApiOperation(value = "所有商户运营区", notes = "所有商户运营区,权限：")
    RestResult<List<GeoMerchantRegion>> all() {
        return regionService.all();
    }

    @GetMapping("")
    @ApiOperation(value = "商户运营区列表", notes = "商户运营区列表,权限：")
        //    @PermissionScope(names = {""})
    RestResult<Page<MerchantCategoryPagePresenter>> getPage(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser,
                                                            @Valid MerchantWrapper wrapper) {
        return regionService.getPage(adminUser, wrapper);
    }

    @PostMapping("")
    @ApiOperation(value = "商户运营区添加", notes = "商户运营区添加,权限：")
        //    @PermissionScope(names = {""})
    RestResult add(@Valid @RequestBody MerchantWrapper wrapper) {
        return regionService.add(wrapper);
    }

    @PatchMapping("/{id}")
    @ApiOperation(value = "商户运营区修改", notes = "商户运营区修改,权限：")
        //    @PermissionScope(names = {""})
    RestResult update(@PathVariable("id") Long id,
                      @Valid @RequestBody MerchantWrapper wrapper) {
        return regionService.update(id, wrapper);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "商户运营区删除", notes = "商户运营区删除,权限：")
        //    @PermissionScope(names = {""})
    RestResult delete(@PathVariable("id") Long id) {
        return regionService.delete(id);
    }

}